<?php
/**
 * Created by PhpStorm.
 * User: UEWARE
 * Date: 2019-8-29
 * Time: 10:17:16
 */

namespace App\Http\Controllers\WeChat;

use App\Factory\Qiniu;
use Illuminate\Http\Request;

class UploadController extends WeChatController
{
    /**
     * 图片上传
     *
     * @param Request $request
     * @param Qiniu $qiniu
     * @return \Illuminate\Http\JsonResponse|void
     */
    public function index(Request $request, Qiniu $qiniu)
    {
        $file = $request->file('file');

        // 判断为空
        if (!$file) {
            return error(600000);
        }

        $url = $qiniu->upload($file, $this->userId);

        return success(['url' => $url]);
    }
}